#include "Line.hpp"
#include <iostream>
using std::cout;
using std::endl;
using std::ostream;

//一般来说编译器会从上到下进行扫描
//在类中会扫描完全部内容再进行编译
//
//一般情况会把内部类定义在外部类的private区域

class Line::LineImpl{
/* public: */
    class Point{
    public:
        Point(int ix ,int iy = 0)
            : _ix(ix)
              , _iy(iy)
        {
            cout << "Point(int=0,int=0)" << endl;
        }

        Point(){
            cout << "Point()" << endl;
        }

        void print() const{
            cout << "(" << _ix
                << "," << _iy
                << ")" ;
        }

        ~Point(){cout << "~Point()" << endl;}
    private:
        int _ix;
        int _iy;
    };
public:
    LineImpl(){}

    LineImpl(int x1,int y1,int x2,int y2)
    : _pt1(x1,y1)
    , _pt2(x2,y2)
    { cout << "LineImpl(int * 4)" << endl; }

    void printLine() const{
        _pt1.print();
        cout << "--->";
        _pt2.print();
        cout << endl;
    }

    ~LineImpl(){ cout << "~LineImpl()" << endl; }
private:
    Point _pt1;
    Point _pt2;
    /* double z; */
};

Line::Line(int x1,int y1,int x2,int y2)
: _pimpl(new LineImpl(x1,y1,x2,y2))
{
    cout << "Line(int * 4) " << endl;
}

Line::~Line(){
    cout << "~Line()" << endl;
    if(_pimpl){
        delete _pimpl;
        cout << "over" << endl;
        _pimpl = nullptr;
    }
}

void Line::printLine() const{
    _pimpl->printLine();
}


